<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改售后信息')" />
	<th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-sale-edit" th:object="${sale}">
			<input id="saleId" name="saleId" type="hidden" th:field="*{saleId}"/>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">设备名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="deviceName" id="deviceName" th:field="*{deviceName}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">设备编号：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="deviceCode" id="deviceCode" th:field="*{deviceCode}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">原因：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="cause" id="cause" th:field="*{cause}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">状态：</label>
				<div class="col-sm-8">
					<label class="toggle-switch switch-solid">
                        <input type="checkbox" id="status" th:checked="${sale.status == '0' ? true : false}">
                        <span></span>
                    </label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control" type="text" th:field="*{remark}">
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">

		$("#form-sale-edit").validate({
			onkeyup: false,
		    focusCleanup: true
		});

		function edit() {
			var saleId = $("input[name='saleId']").val();
			var deviceName = $("input[name='deviceName']").val();
			var deviceCode = $("input[name='deviceCode']").val();
			var cause = $("input[name='cause']").val();
			var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
			var remark = $("input[name='remark']").val();
			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "system/sale/edit",
				data : {
					"saleId": saleId,
					"deviceName": deviceName,
					"deviceCode": deviceCode,
					"cause": cause,
					"status": status,
					"remark": remark
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
		}

		function submitHandler() {
	        if ($.validate.form()) {
	        	edit();
	        }
	    }
	</script>
</body>
</html>
